<?php

################################################################################################################
Function show_search_form()
{
	Print("
		<div id=\"box\">
			<form action=\"users.php?page=search\" method=POST>
			<h3>Nom: <input type=text name=\"name\"> <input type=submit value=\"Rechercher\"></h3>
			<input type=hidden name=\"act\" value=\"search\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=10%><b><font color=royalblue>Type:</font></b></td>
					<td>
						<select name=\"type\">
							<option value=\"1\" selected>Tous type</option>
							<option value=\"2\">Utilisateur</option>
							<option value=\"3\">Groupe</option>
						</select>
					</td>
				</tr>
			</table>
		</div>
	");
	return;
}

################################################################################################################
Function show_users_search($start, $limit, $name)
{
  $table_users_auth = $_SESSION['prefix']."users_auth";
  $table_users_infos = $_SESSION['prefix']."users_infos";
  
	$connection = dbconnect();
	$req = dbquery("SELECT uid,login,mail FROM $table_users_auth WHERE login LIKE \"$name%\" ORDER BY uid ASC LIMIT $start,$limit", $connection);
	if (@mysql_num_rows($req) == 0)
	{
		mysql_close($connection);
		return (-1);
    }
   
	while ($line = @mysql_fetch_array($req))
    {
		$req_2 = dbquery("SELECT last_login,valid FROM $table_users_infos WHERE uid=\"$line[uid]\"", $connection);
		$last_login = mysql_result($req_2, 0, "last_login");
		$valid = mysql_result($req_2, 0, "valid");
		
		if ($valid == "ko")
			$class = "red";
		else
			$class = "blue";
			
			Print("
				<thead>
				<tr class=\"$class\">
					<td align=center><font color=green>$line[uid]</font></td>
					<td align=left><font color=darkblue><b>$line[login]</b></font></td>
					<td align=left><font color=#4B4B4B>$line[mail]</font></td>
					<td align=left><font color=#4B4B4B>$last_login</font></td>
					<td align=center>
			");
			if (!is_administrator($line['uid'], $connection))
			{
				Print("
					<a href=\"ipage.php?height=270&act=user&sub=infos&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Informations utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user.png\" width=16 height=16 title=\"Informations sur l'utilisateur $line[login]\"></a> ' 
					<a href=\"ipage.php?height=430&act=user&sub=edit&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_edit.png\" width=16 height=16 title=\"Modifier l'utilisateur $line[login]\"></a> ' 
					<a href=\"ipage.php?height=200&act=user&sub=delete&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_delete.png\" width=16 height=16 title=\"Supprimer l'utilisateur $line[login]\"></a>
				");
			}
			else
			{
				if (!is_root($_SESSION['login'], $connection))
					Print(" - ");
				else
				{
					Print("
						<a href=\"ipage.php?height=270&act=user&sub=infos&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Informations utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user.png\" width=16 height=16 title=\"Informations sur l'utilisateur $line[login]\"></a> ' 
						<a href=\"ipage.php?height=430&act=user&sub=edit&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_edit.png\" width=16 height=16 title=\"Modifier l'utilisateur $line[login]\"></a> ' 
						<a href=\"ipage.php?height=200&act=user&sub=delete&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_delete.png\" width=16 height=16 title=\"Supprimer l'utilisateur $line[login]\"></a>
					");
				}
			}
			Print("						
					</td>
				</tr>
				</thead>
			");
	}
	mysql_close($connection);
	return (0);
}

################################################################################################################
Function show_groups_search($start, $limit, $name)
{
  $table_groups = $_SESSION['prefix']."groups";

	$req = dbquery("SELECT gid,title,description FROM $table_groups WHERE title LIKE \"$name%\" ORDER BY gid ASC LIMIT $start,$limit");
	if (@mysql_num_rows($req) == 0)
		return (-1);
   
	while ($line = @mysql_fetch_array($req))
    {
			
			Print("
				<thead>
				<tr class=\"$class\">
					<td align=center><font color=green>$line[gid]</font></td>
					<td align=left><font color=darkblue><b>$line[title]</b></font></td>
					<td align=left><font color=#4B4B4B>$line[description]</font></td>
					<td align=center>
						<a href=\"ipage.php?height=230&act=group&sub=infos&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Informations groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group.png\" width=16 height=16 title=\"Informations sur le groupe $line[title]\"></a>
			");
			if (($line['gid'] != 1) && ($line['gid'] != 2))
			{
				Print("
					' 
					<a href=\"ipage.php?height=270&act=group&sub=edit&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group_edit.png\" width=16 height=16 title=\"Modifier le groupe $line[title]\"></a> ' 
					<a href=\"ipage.php?height=200&act=group&sub=delete&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group_delete.png\" width=16 height=16 title=\"Supprimer le groupe $line[title]\"></a>
				");
			}
			Print("						
					</td>
				</tr>
				</thead>
			");
	}
	return (0);
}

?>